package com.zong.bo.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.dubbo.config.annotation.Reference;
import com.zong.bo.service.UserService;
import com.zong.core.bean.Result;

@RestController
public class UserController {
	@Reference(version = "1.0.0")
	private UserService userService;

	@Autowired
	private RedisTemplate<Object, Object> redisTemplate;

	@RequestMapping("/say")
	public String say(String msg) {
		return userService.say(msg);
	}

	@RequestMapping("/users")
	public Result users() {
		Result result = Result.success();
		result.put("rows", userService.findUsers());
		return result;
	}

	@RequestMapping("/{table}")
	public Result table(@PathVariable String table) {
		Result result = Result.success();
		result.put("rows", userService.find(table));

		redisTemplate.opsForValue().set("bo:data", result);
		return result;
	}

	@RequestMapping("/data")
	public Result data() {
		return (Result) redisTemplate.opsForValue().get("bo:data");
	}
}
